//
//  MainTB.swift
//  swift微博
//
//  Created by CC on 16/2/26.
//  Copyright © 2016年 CC. All rights reserved.
//

import UIKit
//1.代理协议
@objc protocol MainTabBarButtonDeleget: NSObjectProtocol{
     optional
    func MainTabBarButtonDidClick()
}

class MainTB: UITabBar {
    //2.代理属性
    weak var buttonDelegate : MainTabBarButtonDeleget?
    
    //3.调用代理
    func buttonClick(button : UIButton){
        
        self.buttonDelegate? .MainTabBarButtonDidClick?()
    }
    
    override func layoutSubviews() {
        // 设置frame宽度扯大一点
        // 5表示5个item
        let width = frame.width / 5
        composeButton.frame = CGRect(x: 0, y: 0, width: width + 5 , height: frame.height)
        
        // 设置中心点
        composeButton.center = CGPoint(x: frame.width * 0.5, y: frame.height * 0.5)
    }

    //mark 懒加载中间加号按钮
    lazy var composeButton:UIButton = {
        let button = UIButton()
        // 设置
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        
        button.sizeToFit()
        
        // 添加点击事件
        button.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
        
    }()

}
